package sgg_hsp_data_structures._06_sort;

import java.util.Arrays;

public class SelectSort {


    public static void main(String[] args) {
        int[] arr = ArrUtils.getArr();

//        System.out.println("排序前");
//        System.out.println(Arrays.toString(arr));

        ArrUtils.printCurTime();
        selectSort(arr);
        ArrUtils.printCurTime();

//        System.out.println("排序后");
//        System.out.println(Arrays.toString(arr));
    }

    public static void selectSort(int[] arr) {

        for (int i = 0; i < arr.length - 1; i++) {
            int minIndex = i;
            int min = arr[i];
            for (int j = i + 1; j < arr.length; j++) {
                if (min > arr[j]) {
                    min = arr[j];
                    minIndex = j;
                }
                if (minIndex != i) {
                    arr[minIndex] = arr[i];
                    arr[i] = min;
                }
            }
        }
    }
}
